import { ObjCreate } from "../common/ObjCreate";
import { TitleItem } from "../common/item/TitleItem";
import { Language } from "../../../../extend/language/Language";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { TilePanel } from "../equipment/TilePanel";
import { ArenaBattleCellRenderer } from "./cellRendener/ArenaBattleCellRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class ArenaBattlesPanel
    
    export  class ArenaBattlesPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 581, 400, this);
            var loc1=new Vector.<TitleItem>();
            loc1.push(new TitleItem(Language.getString(42210), 100));
            loc1.push(new TitleItem(Language.getString(42211), 60));
            loc1.push(new TitleItem(Language.getString(42212), 60));
            var loc2=ObjTeamCreate.createTitles(loc1);
            ObjCreate.setObjAttri(loc2, 13, 8, -1, -1, this);
            var loc3=ObjTeamCreate.createTitles(loc1);
            ObjCreate.setObjAttri(loc3, 290, 8, -1, -1, this);
            this._battleListPanel = new TilePanel();
            this._battleListPanel.setSize(560, 340);
            this._battleListPanel.rowHeight = 34;
            this._battleListPanel.columnWidth = 560;
            this._battleListPanel.setStyle("cellRenderer", ArenaBattleCellRenderer);
            this._battleListPanel.x = 13;
            this._battleListPanel.y = 30;
            this.addChild(this._battleListPanel);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.x = 228;
            this._pageSelecter.y = 374;
            this.addChild(this._pageSelecter);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onChange);
            this._btnRefresh = ObjCreate.createGButton(Language.getString(42213), 389, 371, 54, 22, this);
            this._btnRefresh.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnRefreshClick);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaGetArenaBattles, null));
            return;
        }

        /* internal  */onBtnRefreshClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaGetArenaBattles, null));
            return;
        }

        public updateArenaBattlesData(arg1: Array<any>): void
        {
            this._battleList = arg1;
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.maxPage = Math.ceil(this._battleList.length / this.pageSize);
            this.updateList();
            return;
        }

        /* internal  */onChange(arg1: Object /* flash.events.Event */): void
        {
            this.updateList();
            return;
        }

        /* internal  */updateList(): void
        {
            this._battleListPanel.dataProvider = this.getDataProvider();
            return;
        }

        /* internal  */getDataProvider(): DataProvider
        {
            var loc1=new Array<any>();
            var loc2=(this._pageSelecter.currentPage - 1) * this.pageSize;
            var loc3=Math.min(this._pageSelecter.currentPage * this.pageSize, this._battleList.length);
            var loc4=loc2;
            while (loc4 < loc3) 
            {
                loc1.push(this._battleList[loc4]);
                ++loc4;
            }
            return new DataProvider(loc1);
        }

        /* internal */ /* const */pageSize: int=10;

        /* internal */ /* var */_battleListPanel: TilePanel;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_btnRefresh: GButton;

        /* internal */ /* var */_battleList: Array<any>;
    }
